#include"chen.h"

void sig_pipe( int signo );

void str_cli( FILE *fp, int sockfd );

int
main( int argc, char *argv[] )
{
	char sendline[MAXLINE], recvline[MAXLINE];
	int sockfd;

	sig_t sig;

	void sig_pipe( int );
	
	struct sockaddr_in servaddr;

	if ( argc != 2 )
		err_quit( "usage: ip<address>" );

	sockfd = Socket( AF_INET, SOCK_STREAM, 0 );

	bzero( &servaddr, sizeof( servaddr ) );
	servaddr.sin_family = AF_INET;
	servaddr.sin_port = htons( 13 );
	inet_pton( AF_INET, argv[1], &servaddr.sin_addr );

	sig = signal( SIGPIPE, sig_pipe );

	Connect( sockfd, ( struct sockaddr * ) &servaddr, sizeof( servaddr ) );

	sleep( 2 );

	fgets( sendline, MAXLINE, stdin ); 
	writen( sockfd, sendline, strlen( sendline ) );

	sleep( 2 );

	fgets( sendline, MAXLINE, stdin ); 
	writen( sockfd, sendline, strlen( sendline ) );

	signal( SIGPIPE, sig );

	//str_cli( stdin, sockfd );
	
	exit( 0 );
}

void sig_pipe( int signo )
{
	printf( "SIGPIPE\n" );
	return;
}
